package day12.homework;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Register {
		public static void main(String[] args) {
				Scanner sca = new Scanner(System.in);
				List list = new ArrayList();  //new 集合放在循环外面。
				
				outer:while(true){
					Map map = new HashMap();		//new 元素放在循环里面
					while(true){
					System.out.println("please enter your name:");
					String name = sca.next();
					if("over".equalsIgnoreCase(name)) break outer;
					if(name.matches("^[A-Za-z0-9]{5,8}$")){
						map.put("name", name);
						break;
					}
				}
					while(true){
						System.out.println("please enter your password");
						String password = sca.next();
						if(password.matches("^[A-Za-z0-9]{5,8}$")){
							map.put("password", password);
							break;
						}					
					}
				while(true){
					System.out.println("plase enter your email:");
					String email = sca.next();
					if(email.matches("^[A-Za-z0-9_-]+[@][A-Za-z0-9_-]+(\\.com|\\.com.cn|\\.net|\\.org|\\.cn)$")){
						map.put("email",email);
						break;
					}					
				}
				list.add(map);	
				}
				
				for(int i=0; i<list.size(); i++){
					Object ob = list.get(i);
					if(ob instanceof Map){
						Map map = (Map)ob;
							Object obj = map.get("name");
						if(obj instanceof String){
							String n =(String)obj;
							if(n.startsWith("li")){
								System.out.println(map);
							}
						}
			}
						
		}
					
	}
}

//要求用ArrayList实现可以用户多次注册，在用户名处输入over的时候，用break标签退出外层循环，然后找出姓li的
